/**
 * Created by Administrator on 2017/10/27.
 */
$(function(){
    //==============加载菜单 start=============================
    $.ajax({
        url:url+'getFlowerType',
        dataType:'json',
        type:'post',
        async:false,
        data:{},
        success:function(result){
            // console.log(result);
            var status = result.status;
            var code = result.code;
            if(status==1&&code=='1001'){
                var htmls='<li><a href="#id1">首页</a></li>';
                var data = result.data;
                if(data.length>0){
                    for(var i=0;i<data.length;i++){
                        htmls +='<li><a href="#id'+(data[i]["id"]+1)+'">'+data[i]["name"]+'</a></li>';
                    }
                    $('#menus').html(htmls);
                }
            }
        },
        error:function(result) {
            console.log("error")
        }

    });
    //==============加载菜单 end=============================
    //=============加载首页数据 start========================
    $.ajax({
        url:url+'getHomepage',
        dataType:'json',
        type:'post',
        async:false,
        data:{},
        success:function(result){
            console.log(result);
            var status = result.status;
            var code = result.code;
            if(status==1&&code=='1001'){
                var arr =[];
                var data = result.data;
                if(typeof(data['1'])!='undefined'){
                    arr[1] = data['1'];
                }
                if(typeof(data['2'])!='undefined'){
                    arr[2] = data['2'];
                }
                if(typeof(data['3'])!='undefined'){
                    arr[3] = data['3'];
                }
                if(typeof(data['4'])!='undefined'){
                    arr[4] = data['4'];
                }
                if(typeof(data['5'])!='undefined'){
                    arr[5] = data['5'];
                }
                if(typeof(data['6'])!='undefined'){
                    arr[6] = data['6'];
                }
                console.log(arr);
                if(arr.length>0){
                    var html='';
                    var html2='';

                    for(var i=1;i<arr.length;i++){
                        if(typeof(arr[i])=='undefined'){
                             continue;
                        }
                        if(i==1||i==2||i==3||i==4){
                            html += '<a href="#id'+(i+1)+'"'+' class="product"> <dl><dt class="product_smtitle"><img src="'+arr[i][0]['homepagetitile']+'" alt=""></dt>'+
                                '<dd class="product_conimg"><img src="'+arr[i][0]['homepage']+'" alt=""></dd></dl></a>';
                           continue;
                        }
                        if(i==5){
                            html2 =' <div><p class="product_smtitle" style="padding-bottom:34.133%"><img src="'+arr[5]['title'][0]['homepagetitile']+'" alt=""></p></div><div class="two_layout p15" style="margin-top:30px;">';
                            var datas = arr[5]['content'];
                            for(var j=0;j<datas.length;j++){
                                html2 +='<a href="details.html?id='+datas[j]['id']+'"><u><img  src="'+datas[j]['coverimg']+'" alt=""></u>' +
                                    '<p class="product_p f16"><span>'+datas[j]['name']+'</span></p>'+
                                    '<p class="product_money f16">￥'+datas[j]['price']+'元</p>'+
                                    '</a>';
                            }
                           if(datas.length==0){
                              html2 +='<span style="text-align:center;width:25rem;color:red">新产品还没有上架，敬请期待</span>';
                            }
                            html2 +='</div>';
                            $('#id6').html(html2);
                           continue;
                        }

                        if(i==6){
                            html2='<div><p class="product_smtitle" style="padding-bottom:34.133%"><img src="'+arr[6]['title'][0]['homepagetitile']+'" alt=""></p></div><div class="two_layout p15" style="margin-top:30px;">';
                            var datas = arr[6]['content'];
                            for(var j=0;j<datas.length;j++){
                                html2 +='<a href="details.html?id='+datas[j]['id']+'"><u><img  src="'+datas[j]['coverimg']+'" alt=""></u>' +
                                    '<p class="product_p f16"><span>'+datas[j]['name']+'</span></p>'+
                                    '<p class="product_money f16">￥'+datas[j]['price']+'元</p>'+
                                    '</a>';
                            }
                          if(datas.length==0){
                              html2 +='<span style="text-align:center;width:25rem;color:red">新产品还没有上架，敬请期待</span>';
                            }
                            html2 +='</div>';
                            $('#id7').html(html2);
                           continue;
                        }
                    }
                    $('.product_out').html(html);
                }
            }
        },
        error:function(result) {
            console.log("error")
        }

    });
    //=============加载首页数据 end==========================
    //=============轮播图 start============

    window.swiper_init = null;
    lunbo();
    function lunbo(){
        if(window.swiper_init != null){
            return;
        }
        $.ajax({
            url:url+'getlunbo',
            dataType:'json',
            type:'post',
            async:false,
            data:{},
            success:function(result){
                // console.log(result);
                var status = result.status;
                var code = result.code;
                if(status==1&&code=='1001'){
                    var data = result.data;

                    if(data.length>0){
                        var htmls='';
                        for(var i=0;i<data.length;i++){
                            htmls += '<li class="swiper-slide"> <a href="#" class="banner-mob">'
                                +'<img src="'+data[i]+'" alt="灰姑娘" ></a></li>';
                        }

                        $('.swiper-wrapper').html(htmls);
                        $('.banner').css('height',$(".banner").width()*0.5+"px");
                        window.swiper_init = new Swiper('.banner', {
                            loop: true,
                            autoplay:3500,
                            pagination:'.swiper-pagination',
                            paginationClickable:true,
                            preventClicks:false,
                            autoplayDisableOnInteraction: false,
                            effect:'slide',
                        });
                    }
                }
            },
            error:function(result) {
                console.log("error")
            }

        });

    }

    //=============轮播图 end==============
    //================用户说 start========================
    $.ajax({
        url:url+'getguestsshuo',
        dataType:'json',
        type:'post',
        async:false,
        data:{},
        success:function(result){
            // console.log(result);
            var status = result.status;
            var code = result.code;
            if(status==1&&code=='1001'){
                var data = result.data;
                if(data.length>0){
                    var htmls='';
                    for(var i=0;i<data.length;i++){
                        htmls += '<li><img class="usersay_list_img" src="'+data[i]['img']+'" alt="">' +
                            '<p>'+data[i]['content']+'</p>'+
                        '<div class="usersay_info"><div class="avator"><img src="'+data[i]['headimg']+'"><span>'+data[i]['nickname']+'</span></div>'+
                            '<div class="fl_r"><span class="pv"></span></div></div></li>';
                    }
                    $('.usersay_list_ul').html(htmls);
                }
            }
        },
        error:function(result) {
            console.log("error")
        }

    });
    //================用户说 end==========================
    //==============logo图片以及用户说图片 start==================
    $.ajax({
        url:url+'getlogos',
        dataType:'json',
        type:'post',
        async:false,
        data:{},
        success:function(result){
            // console.log(result);
            var status = result.status;
            var code = result.code;
            if(status==1&&code=='1001'){
                var data = result.data;
                $('.logos').attr('src',data['logo']);
                $('.yonghushuo').attr('src',data['guestshuo']);
            }
        },
        error:function(result) {
            console.log("error")
        }

    });
    //==============logo图片以及用户说图片 end====================
})
